#include "head.h"

int main(void)
{
    // 初始化进程池
    Process pool[N];
    bzero(pool, N);
    init_pool(pool, N);
    printf("初始化进程池\n");

    // 绑定端口 开始监听
    int fd;
    main_tcp(&fd, IP, PORT);

    int epoll_fd = epoll_create(1);
    epoll_pool_add(fd, epoll_fd);
    printf("等待第一个用户任务\n");
    while(1)
    {
        struct epoll_event events[N];
        bzero(events, sizeof(events));
        // 监听任务
        int count = epoll_wait(epoll_fd, events, N, -1);
        printf("count = %d\n", count);
        for(int i = 0; i < count; ++i)
        {
            int current_fd = events[i].data.fd;
            if(current_fd == fd)
                // 添加新用户
                add_usr(fd, current_fd, epoll_fd);
                
            else
                // 分配任务
                allocating_task(pool, N, current_fd, epoll_fd);
        }
    }
    return 0;
}